package com.umanji.building.service;

import java.util.ArrayList;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.umanji.building.domain.PublicOfficialBuildingBoards;
import com.umanji.generic.service.GenericService;


@Service("pobBoardService")
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class PublicOfficialBuildingBoardServiceImpl extends GenericService<PublicOfficialBuildingBoards, Long> implements PublicOfficialBuildingBoardService {

	private final Log log = LogFactory.getLog ( PublicOfficialBuildingBoardServiceImpl.class );
    
    public void getBoardReadCount(Long boardId){
    	// em.getTransaction().begin();
    	em.createQuery("update "+ PublicOfficialBuildingBoards.class.getSimpleName()+" b set b.readCount = b.readCount+1 where b.id = :boardId ").setParameter("boardId", boardId).getFlushMode();
    	System.out.println("쿼리 아랫줄");
    	// em.getTransaction().commit();
    	// em.close();
    }

    public List findByBoardId(Long boardId, int firstResult, int maxResults){
    	return super.em.createQuery("select t from "+PublicOfficialBuildingBoards.class.getSimpleName()+" t where t.id = :boardId ").setParameter("boardId", boardId).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

}
